import 'package:kxy_flutter_app/auth.dart';
import 'package:kxy_flutter_app/helper/http.dart';
import 'package:kxy_flutter_app/model/course_resource.dart';

class IntegralService {
  static Future addNotice(String noticeId) async {
    await Http.instance.post('/integral-app/integral/userGrade/addGrade', params: {
      'userId': Auth.instance.userId,
      'pCode': 300000,
      'cCode': 300001,
      'reId': noticeId,
    });
  }

  static Future addViewNews(String newsId) async {
    await Http.instance.post('/integral-app/integral/userGrade/addGrade', params: {
      'userId': Auth.instance.userId,
      'pCode': 200000,
      'cCode': 200001,
      'reId': newsId,
    });
  }

  static Future addCourseCompleted(String courseId) async {
    await Http.instance.post('/integral-app/integral/userGrade/addGrade', params: {
      'userId': Auth.instance.userId,
      'pCode': 600000,
      'cCode': 600005,
      'reId': courseId,
    });
  }

  static Future addCourseResourceCompleted(String resourceId, ResourceType type) async {
    int pCode = 600000;
    int cCode = 0;

    switch (type) {
      case ResourceType.Video:
        cCode = 600001;
        break;
      case ResourceType.Picture:
        cCode = 600002;
        break;
      case ResourceType.Document:
        cCode = 600003;
        break;
      case ResourceType.Exam:
        cCode = 600004;
        break;
      default:
        break;
    }

    await Http.instance.post('/integral-app/integral/userGrade/addGrade', params: {
      'userId': Auth.instance.userId,
      'pCode': pCode,
      'cCode': cCode,
    });
  }
}

enum IntegralType {
  ViewNews,
  CourseResourceCompleted,
}
